<template>
	<jk-dialog
		v-model="showDialog"
		:title="`${dataItem.machineName}-详情`"
		width="1140px"
		append-to-body
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		:show-close-btn="true"
		@on-visible-change="onVisibleChange"
		@on-close="onVisibleChange(false)"
	>
		<header ref="box1" class="margin-bottom-10 flex-between-center">
			<div class="flex-start-center-wrap">
				<!--<el-checkbox v-model="isCustomTime" label="自定义查询时间" border size="small" @change="onCustomTimeChange"></el-checkbox>-->
			</div>
			<div class="flex-start-center">
				<!--<jk-select v-model="searchParams.workshopId" clearable placeholder="区域" :option-list="workshopList" size="small" class="search-bar-item-size1 margin-5-0 item-gap"></jk-select>-->
				<!--<jk-select v-model="searchParams.processCode" clearable placeholder="工序" value-key-name="code" :option-list="processList" size="small" class="search-bar-item-size1 margin-5-0 item-gap"></jk-select>-->
				<!--<jk-date-picker v-show="!isCustomTime" v-model="searchParams.belongDate" type="date" clearable placeholder="日期" size="small" class="search-bar-item-size2 margin-5-0 item-gap"></jk-date-picker>-->
				<!--<jk-select v-show="!isCustomTime" v-model="searchParams.shiftId" clearable placeholder="班次" :option-list="shiftList" size="small" class="search-bar-item-size1 margin-5-0 item-gap"></jk-select>-->
				<!--<jk-date-picker v-show="isCustomTime" v-model="searchParams.dateTimeRange" type="datetimerange" clearable start-placeholder="开始时间" end-placeholder="结束时间" size="small" style="width: 380px" class="margin-5-0 item-gap"></jk-date-picker>-->
				<jk-search-button @click="onSearchBtn"></jk-search-button>
			</div>
		</header>

		<jk-table
			ref="jkTable"
			:loading="tableLoading"
			class="width-100-percent"
			:data="tableData"
			border
			highlight-hover-row
			highlight-current-row
			:height="dialogTableHeight - 30"
		>
			<!--<vxe-table-column field="machineName" title="机台" fixed="left" :width="80"></vxe-table-column>-->
			<vxe-table-column field="timeString" title="停止时长" :width="80"></vxe-table-column>
			<vxe-table-column field="output" title="产量(M)" align="right" :width="90"></vxe-table-column>
			<vxe-table-column field="outputKg" title="产量(kg)" align="right" :width="90"></vxe-table-column>
			<vxe-table-column field="beginTime" title="开始时间" align="left" :width="150"></vxe-table-column>
			<vxe-table-column field="endTime" title="结束时间" align="left" :width="150"></vxe-table-column>
			<vxe-table-column field="stopStartOutput" title="停止开始时产量" align="right" :width="110"></vxe-table-column>
			<vxe-table-column field="stopEndOutput" title="停止结束时产量" align="right" :width="110"></vxe-table-column>
			<vxe-table-column field="productName" title="品种" :min-width="180"></vxe-table-column>
			<vxe-table-column field="batchCode" title="批号" :width="140"></vxe-table-column>
		</jk-table>
		<footer ref="box2" class="flex-end-center margin-top-10">
			<jk-page
				:page-index="searchParams.pageNo"
				:page-sizes="searchParams.pageSizes"
				:page-size="searchParams.pageSize"
				:total="totalCount"
				layout="total, prev, pager, next"
				@on-change="onPageChange"
			/>
		</footer>
	</jk-dialog>
</template>

<script>
    import calDialogHeight from '../../../mixins/cal-dialog-height';
    import { pageConfig } from '../../../utils/jk/jk-tool';
    import { productionMachineIneffectiveYieldRecordsPage } from '../../../api/production/reports';

    export default {
        mixins: [calDialogHeight],
        props: {
            dataItem: {
                type: Object,
                default() {
                    return {};
                }
            },
            dialogState: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
                shiftList: [],
                processList: [],
                workshopList: [],
                isCustomTime: false,
                searchParams: {
                    pageNo: pageConfig.pageNo,
                    pageSize: pageConfig.pageSize
                },
                searchBarProcessId: null,
                searchBarNameOrCode: '',
                tableData: [],
                showDialog: false,
                tableLoading: false,
                totalCount: null
            };
        },
        methods: {
            onCustomTimeChange(e) {
                if (e) {
                    this.$set(this.searchParams, 'belongDate', null);
                    this.$set(this.searchParams, 'shiftId', null);
                } else {
                    this.$set(this.searchParams, 'dateTimeRange', []);
                }
            },
            onCellDblclick(e) {
                this.$emit('on-confirm', e.row);
            },
            onSearchBtn() {
                this.$set(this.searchParams, 'pageNo', 1);
                this.getListRequest();
            },
            onPageChange(e, size) {
                this.$set(this.searchParams, 'pageNo', e);
                this.$set(this.searchParams, 'pageSize', size);
                this.getListRequest();
            },
            getListRequest() {
                this.tableLoading = true;
                return productionMachineIneffectiveYieldRecordsPage(this.searchParams).then(res => {
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        this.totalCount = res.data.count;
                        this.tableData = res.data.res;
                    }
                });
            },
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                }
            },
            async getDependentData() {
                this.tableLoading = true;
                await this.getListRequest();
            }
        },
        watch: {
            formData: {
                handler(newVal) {
                },
                deep: true,
                immediate: true
            },
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.searchParams = {
                        ...JSON.parse(JSON.stringify(this.dataItem)),
                        ...this.searchParams
                    };
                    this.getDependentData();
                }
            }
        }
    };
</script>

